package com.money.shell.view
{
	import com.money.shell.ShellFacade;
	import com.money.shell.model.vo.MenuVo;
	import com.money.shell.view.ui.Frame;
	import com.money.shell.view.ui.MenuBar;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.collections.XMLListCollection;
	import mx.controls.Alert;
	import mx.controls.Image;
	import mx.core.IVisualElementContainer;
	import mx.events.FlexEvent;
	import mx.events.ModuleEvent;
	import mx.modules.IModuleInfo;
	import mx.modules.ModuleManager;
	import mx.utils.ArrayUtil;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class FrameMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "FrameMediator";
		
		public var module:IModuleInfo;
		public function FrameMediator(viewComponent:Frame)
		{
			super(NAME, viewComponent);
		}
		private function get frame():Frame
		{
			return viewComponent as Frame;
		}
		override public function onRegister():void
		{
		}
		override public function onRemove():void
		{
		}
		override public function listNotificationInterests():Array
		{
			return [ShellFacade.LOADMODULE,];
		}
		
		public function loadModule(modulePath:String):void
		{
			module=ModuleManager.getModule(modulePath);
			module.addEventListener(ModuleEvent.READY, moduleReadyHandle);
			module.load();
		}
		public function moduleReadyHandle(event:ModuleEvent):void
		{
			frame.removeAllElements();
			frame.addElement(module.factory.create() as IVisualElement);
		}
		override public function handleNotification(note:INotification):void
		{
			switch (note.getName())
			{
				case ShellFacade.LOADMODULE:
					var menuVo:MenuVo=note.getBody() as MenuVo;
					loadModule(menuVo.path);
					break;
			}
		}
	}
}